package com.chenliang.testfilter.filter;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: springboot-filter
 * @description:
 * @author: chenLiang
 * @create: 2022-08-04 16:53
 */
@Component
@Order(5)
public class Filter04 extends OncePerRequestFilter {

    /**
     * 通常 serlvet版本的不同会略有差异。如：servlet2.3与servlet2.4也有一定差异：
     *
     * 在servlet2.3中，Filter会经过一切请求，包括服务器内部使用的forward转发请求和<%@ include file=”/login.jsp”%>的情况
     *
     * servlet2.4中的Filter默认情况下只过滤外部提交的请求，forward和include这些内部转发都不会被过滤，
     *
     * 作者：善思者_tin
     * 链接：https://www.jianshu.com/p/de66fc745da8
     * 来源：简书
     * 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。
     *
     * @param httpServletRequest
     * @param httpServletResponse
     * @param filterChain
     * @throws ServletException
     * @throws IOException
     */


    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        System.out.println("Filter04 执行业务逻辑");
        filterChain.doFilter(httpServletRequest, httpServletResponse);
    }
}
